
define([
    "jquery",
    "IO",
    "UPLOADUI",
    "UPLOAD",
    "jqueryUI",
    "bootbox",
    //"text!/js/biz/keb/activity/definebt.html"
], function ($, IO, upui, up, jui, bootbox, definebt) {
    $('#fileupload').fileupload({
        url: '/upload',
        dataType: 'json',
        autoUpload: true,
        acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
        maxFileSize: 10000000, // 10 MB
        disableImageResize: /Android(?!.*Chrome)|Opera/
            .test(window.navigator.userAgent),
        previewMaxWidth: 150,
        previewMaxHeight: 150,
        previewCrop: true
    }).on('fileuploadadd', function (e, data) {
        document.getElementById('upimgs').src = '/images/loading.gif';

    }).on('fileuploadprocessalways', function (e, data) {
        //console.log("fileuploadprocessalways",data);
    }).on('fileuploadprogressall', function (e, data) {
        //console.log("fileuploadprogressall",data);
    }).on('fileuploaddone', function (e, data) {
        //alert('Img'+youpaiImg);
        //alert(data._response.result.url);
        //document.getElementById('upimgs').src = data._response.result.url;
        //console.log(youpaiImg);
        //  console.log("fileuploaddone",data);
        var alt = $(e.target).attr('alt');
        if (!alt)
            alt = '';
        console.log("#upimgs" + alt);
        $("#upimgs" + alt).attr("src", data._response.result.url);
    });
    $(document).on("click",".publish",function(){

        var major_name = $(".zy option:selected").val();
        var major_id = $(".zy option:selected").attr("data-id");
        var course_name = $("#course_name").val();
        var cover = $("#upimgs").attr("src");
        var sequence = $("#sequence").val();
        var teacher_name = $("#teacher_name").val();
        var course_desc = editor.html();
        var param = {major_name:major_name,major_id:major_id,course_name:course_name,cover:cover,sequence:sequence,teacher_name:teacher_name,course_desc:course_desc};

        if(major_id!=undefined){
            param.major_id = major_id;
        }else{
            alert("请选择专业~");
            return;
        }

        if(course_name==""){
            alert("请输入课程名称");
            return;
        }
        if(cover=="/images/addimg.png"){
            alert("请上传课程照片");
            return;
        }
        if(sequence==""){
            alert("输入课程编号");
            return;
        }
        if(teacher_name==""){
            alert("请输入老师姓名");
            return;
        }
        if(course_desc==""){
            alert("请输入课程描述");
            return;
        }
        if(param&&param!='undefined'){
            bootbox.confirm("确定要添加该课程",function(result){
                if(result) {
                    IO.post("api/addcourse",param,function(d){
                        bootbox.alert(d.msg,function(){
                            if (d.code == 0) {
                                location.href = '/pte/course';
                            }
                        })
                    });
                }
            });
        }
    })
});

